﻿//用于注册页面装载完成后的操作
//打开页面后立刻向misprocess请求收藏和工作认证情况
//过5秒后请求发送增加页面阅读次数
//$(document).ready(function() {
//    GetStatus();
//    setTimeout(function() { UpdateViewTimes(); }, 5000);
//    //window.addEventListener("scroll", function() { SetUserPanelStyle(); });

//});

//用于设置用户控制面板的位置，外观以及其他特性
var SetUserPanelStyle = function() {
    //var top = $["#UserPanel"].y;
    //alert(___getPageScroll().yScroll);



}

//取得页面滚动的x，y值   
function ___getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {     // Explorer 6 Strict   
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers   
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft;
    }
    arrayPageScroll = new Array(xScroll, yScroll);
    return arrayPageScroll;
};  

//用于获取页面传入参数
function request(paras) {
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof (returnValue) == "undefined") {
        return "";
    } else {
        return returnValue;
    }
}

//向MiscProcess请求收藏和工作认证情况xml
var GetStatus = function() {
    setTimeout(function() { UpdateViewTimes(); }, 5000);
    var dataNo = "&DataNo=" + request('DataNo');
    if (typeof (dataNo) != "undefined") {
        $.ajax({
            type: "GET",
            url: "ajax/MiscProcess.aspx",
            async: false,
            cache: false,
            data: dataNo,
            success: function(result) {
                //alert(result);
                if (result != null) {
                    //如果执行到这边说明获取到数据，就设置对应的图片
                    //如果已经添加收藏，就将图片设置为移除收藏
                    //alert(result);
                    //alert($(result).find("Favor").text());
                    if ($(result).find("Favor").text() == "True") {
                        $("#favorImg").attr('src', 'Images/removefavor.png');
                        $("#favorImg").attr('alt', '取消收藏');
                        $("#favorImg").attr('title', '取消收藏');
                    }
                    else {
                        $("#favorImg").attr("src", "Images/addfavor.png");
                        $("#favorImg").attr('alt', '添加收藏');
                        $("#favorImg").attr('title', '添加收藏');
                    }
                    //如果工作已经被认证就显示已经认证图标
                    if ($(result).find("HasConfirmed").text() == "True") {
                        $("#verifyImg").attr("src", "Images/approved.png");
                        $("#verifyImg").attr('alt', '已认证');
                        $("#verifyImg").attr('title', '已认证');
                    }
                    else {
                        if ($(result).find("NeedConfirm").text() == "True") {
                            $("#verifyImg").attr("src", "Images/pending.png");
                            $("#verifyImg").attr('alt', '认证处理中');
                            $("#verifyImg").attr('title', '认证处理中');
                        }
                        else {
                            $("#verifyImg").attr("src", "Images/request.png");
                            $("#verifyImg").attr('alt', '申请工作认证');
                            $("#verifyImg").attr('title', '申请工作认证');
                        }
                    }
                    $("#favorImg").click(function() { OperateFavorList(); });
                    $("#verifyImg").click(function() { RequestConfirm(); });
                }
                else {
                    return;
                }
            }
        });
    }
}

//定时，发送增加已读数量的请求
var UpdateViewTimes = function() {
    var dataNo = "&DataNo=" + request('DataNo');
    if (typeof (dataNo) != "undefined") {
        $.ajax({
            type: "GET",
            url: "ajax/MiscProcess.aspx?&OP=&UpdateViewTimes=&n=" + Math.random(),
            data: dataNo,
            success: function(result) {
                return;
            }
        });
    }
}

//点击收藏
var OperateFavorList = function() {
    var dataNo = "&DataNo=" + request('DataNo');
    if (typeof (dataNo) != "undefined") {
        $.ajax({
            type: "GET",
            url: "ajax/MiscProcess.aspx?&OP=&OpFavor=&n=" + Math.random(),
            data: dataNo,
            success: function(result) {
                window.location.reload();
            }
        });
    }
}

//申请认证
var RequestConfirm = function() {
    var dataNo = "&DataNo=" + request('DataNo');
    if (typeof (dataNo) != "undefined") {
        $.ajax({
            type: "GET",
            url: "ajax/MiscProcess.aspx?OP=&RequestConfirm=&n=" + Math.random(),
            data: dataNo,
            success: function(result) {
                window.location.reload();
            }
        });
    }
}